package com.yang.test;

import java.util.List;

import org.hibernate.cfg.Configuration;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.task.Task;
import org.junit.Test;

public class HelloWord {

	private ProcessEngine engine = new org.jbpm.api.Configuration()
			.setResource("jbpm.cfg.xml")//
			.buildProcessEngine();

	@Test
	public void createSchema() {
		new Configuration().configure("jbpm.hibernate.cfg.xml")
				.buildSessionFactory();
	}

	@Test
	public void deployProcessDefinition() {
		engine.getRepositoryService().createDeployment()
				.addResourceFromClasspath("helloword/helloword.png")
				.addResourceFromClasspath("helloword/helloword.jpdl.xml")
				.deploy();
	}

	@Test
	public void startProcessInstance() {
		engine.getExecutionService().startProcessInstanceByKey("helloword");
	}

	@Test
	public void findMyTaskList() {
		// String userId = "员工";
		// String userId = "部门经理";
		String userId = "总经理";

		List<Task> list = engine.getTaskService().findPersonalTasks(userId);

		System.out.println("======================【" + userId
				+ "】的任务列表=======================");

		for (Task t : list) {
			System.out.println("id=" + t.getId()//
					+ ", name=" + t.getName()//
					+ ", accignee=" + t.getAssignee()//
					+ ", reateTime=" + t.getCreateTime());
		}
	}

	@Test
	public void completeTask() {
		String taskId = "30001";
		engine.getTaskService().completeTask(taskId);
	}
}
